package velha.connection.net;

import java.io.IOException;
import javax.microedition.lcdui.*;
import velha.Menu;
import velha.VelhaMIDlet;

public class NETMenu extends List implements CommandListener {

    private final VelhaMIDlet vmid;

    public NETMenu(VelhaMIDlet vmid) {
        super("Online", List.IMPLICIT);

        this.vmid = vmid;

        try {
            append("Criar jogo", Image.createImage("/img/criar.png"));
            append("Procurar jogo", Image.createImage("/img/procurar.png"));
        } catch (IOException ex) {
        }

        addCommand(new Command("Voltar", Command.BACK, 0));
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        if ("Voltar".equals(c.getLabel())) {
            vmid.getDisplay().setCurrent(new Menu(vmid));
        } else if (c == SELECT_COMMAND) {
            switch (getSelectedIndex()) {
                case 0:
                    NETServer serv = new NETServer(vmid);
                    serv.showGui();
                    new Thread(serv).start();
                    break;
                case 1:
                    NETCliente client = new NETCliente(vmid);
                    client.showGUI();
                    break;
            }
        }
    }
}
